*******************************
* IRCA and Redistricting
* Navid Sabet and Noam Yuchtman
* Table 1: IRCA and Compactness (baseline)
*******************************

	//Load data
	use irca_gerrymander.dta, clear
	 	
	//Controls
	global controls c.pop1990#i.p102 c.inc_pc1990#i.p102  c.age_share1990#i.p102 c.unemployment_1990#i.p102 c.educ1990##i.p102 c.births_1990#i.p102 c.black_share1990#i.p102 c.white_share1990#i.p102 
	
	//VRA Controls
	global vra_control i.vra_covered##i.p102
	
	//Fixed effects
	global fe id congress#StateFIPS i.unassigned_county#i.congress c.hisp_share1980#i.congress 
	
	//Clustering
	global cluster id
	
	//Drop single district states
	drop if single_district1990==1
	 

***********
* Report
***********
	eststo clear
	//Baseline: PP
	reghdfe pp_county $controls $vra_control c.irca_std##i.p102  [weight=cuts], a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Baseline: PP Kaplan Legal Control
	reghdfe pp_county $controls $vra_control c.irca_std##i.p102##ib2.legal_control_kaplan1991 [weight=cuts], a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	sum pp_county if e(sample) & congress==102
	estadd scalar mean_y = r(mean)
	estadd scalar sd_y = r(sd)
	lincom 1.p102#c.irca_std + 1.p102#1.legal_control_kaplan1991#c.irca_std
	estadd scalar sum_1 = r(estimate)
	estadd scalar p_1 = r(p)
	eststo 
	
	//Baseline: Schwartzberg
	reghdfe schw_county $controls $vra_control c.irca_std##i.p102  [weight=cuts], a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Baseline: Schwartzberg Kaplan Legal Control
	reghdfe schw_county $controls $vra_control c.irca_std##1.p102##ib2.legal_control_kaplan1991 [weight=cuts], a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	sum schw_county if e(sample) & congress==102
	estadd scalar mean_y = r(mean)
	estadd scalar sd_y = r(sd)
	lincom 1.p102#c.irca_std + 1.p102#1.legal_control_kaplan1991#c.irca_std
	estadd scalar sum_1 = r(estimate)
	estadd scalar p_1 = r(p)
	eststo 
	
	//Baseline: Reock 
	reghdfe reo_county $controls $vra_control c.irca_std##i.p102 [weight=cuts], a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo
	
	//Baseline: Reock Kaplan Legal Control
	reghdfe reo_county $controls $vra_control c.irca_std##1.p102##ib2.legal_control_kaplan1991 [weight=cuts], a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	sum reo_county if e(sample) & congress==102
	estadd scalar mean_y = r(mean)
	estadd scalar sd_y = r(sd)
	lincom 1.p102#c.irca_std + 1.p102#1.legal_control_kaplan1991#c.irca_std
	estadd scalar sum_1 = r(estimate)
	estadd scalar p_1 = r(p)
	eststo 
	
	//Baseline: CVH 
	reghdfe cvh_county $controls $vra_control c.irca_std##i.p102 [weight=cuts], a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Baseline: CVH Kaplan Legal Control
	reghdfe cvh_county $controls $vra_control c.irca_std##1.p102##ib2.legal_control_kaplan1991 [weight=cuts], a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	sum cvh_county if e(sample) & congress==102
	estadd scalar mean_y = r(mean)
	estadd scalar sd_y = r(sd)
	lincom 1.p102#c.irca_std + 1.p102#1.legal_control_kaplan1991#c.irca_std
	estadd scalar sum_1 = r(estimate)
	estadd scalar p_1 = r(p)
	eststo 
	
	
***********************
*	Generate Table
**********************		


estfe 	est*
esttab  est*	using "tab1.tex", replace booktabs ///
				nonote noobs nogaps compress noeqlines se substitute(_ _) label interaction(" $\times$ ") ///
				mgroups("Polsby-Popper" "Schwartzberg" "Reock" "Convex-Hull", pattern(1 0 1 0 1 0 1 0) ///
				prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
				mtitles("\makecell{Baseline \\ Effect}" "\makecell{Party \\ Effect}" "\makecell{Baseline \\ Effect}" "\makecell{Party \\ Effect}" "\makecell{Baseline \\ Effect}" "\makecell{Party \\ Effect}" "\makecell{Baseline \\ Effect}" "\makecell{Party \\ Effect}") ///
				scalars("N $N$" "clusters Clusters" "mean_y $\bar{Y}_{102}$" "sd_y [S.D]" "sum_1 Sum" "p_1 \hspace{.5em} $p$-value") sfmt(%9.3gc) ///
				star(* 0.1 ** 0.05 *** 0.01) ///
				keep(1.p102#c.irca_std  ///
					1.p102#1.legal_control_kaplan1991#c.irca_std)
							
						
